<!-- 编辑弹窗 -->
<template>
  <el-dialog
    title="补差规则明细"
    :visible="visible"
    width="500px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible">
    <el-form
      ref="form"
      :model="form"
      label-width="140px">
      <el-form-item label="补差依据:" prop="bcname">
        <el-input
          disabled
          v-model="form.bcname"
          placeholder="输入补差依据"/>
      </el-form-item>
      <el-form-item label="适用客户:" prop="invtype">
            <el-select
              disabled
              v-model="form.availableCustomer"
              placeholder="请选择规则适用客户"
              class="ele-fluid">
              <el-option label="全部" value="全部"/>
              <el-option label="医院" value="医院"/>
              <el-option label="商业" value="商业"/>
            </el-select>
      </el-form-item>
      <el-form-item label="产品类型:" prop="invtype">
        <el-select
          disabled
          v-model="form.invtype"
          placeholder="请选择产品类型"
          class="ele-fluid">
          <el-option label="外购" value="外购"/>
          <el-option label="包销" value="包销"/>
        </el-select>
      </el-form-item>
      <el-form-item label="开始日期:" prop="begindate">
        <el-date-picker disabled v-model="form.begindate" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder="选择开始日期" clearable class="ele-fluid"></el-date-picker>
      </el-form-item>
      <el-form-item label="有效期天:" prop="validity">
        <el-select  
          disabled
          v-model="form.validity"
          class="ele-fluid">
          <el-option label="15天" :value="15"/>
          <el-option label="30天" :value="30"/>
        </el-select>
      </el-form-item>
      <el-form-item label="业务结束日期:" prop="enddate">
        <el-date-picker disabled v-model="form.enddate" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' class="ele-fluid"></el-date-picker>
      </el-form-item>
      <el-form-item label="销售管理结束日期:" prop="manageEnddate">
        <el-date-picker disabled v-model="form.manageEnddate" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' class="ele-fluid"></el-date-picker>
      </el-form-item>
      <el-form-item label="超期情况说明:" prop="invtype">
        <a v-bind:href="baseURL+'uploads/'+form.uploadfile" target="_blank" style="text-decoration: underline;">
          {{form.uploadfile?String(form.uploadfile).slice(String(form.uploadfile).indexOf('_')+1):''}}
        </a>
      </el-form-item>
      <el-form-item label="制单人:" prop="createUserName">
        <span>{{ form.createUserName }}</span>
      </el-form-item>
      <el-form-item label="制单时间:" prop="createUserName">
        <span>{{ form.createTime }}</span>
      </el-form-item>
      <el-form-item label="审批人:" prop="createUserName">
        <span>{{ form.approver }}</span>
      </el-form-item>
      <el-form-item label="审批时间:" prop="createUserName">
        <span>{{ form.approveTime }}</span>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">关闭</el-button>
      <el-button
        type="primary"
        @click="approve"
        :loading="loading" 
        v-if="permission.includes('sys:spbcinvset:approve') && form.mark==1">审核
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { mapGetters } from "vuex";
import setting  from '@/config/setting';
export default {
  name: 'SpbcInvsetDetail',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表单数据
      form: {},
      // 提交状态
      loading: false,
      baseURL: setting.baseURL
    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        this.isUpdate = true;
      } else {
        this.form = {},
        this.isUpdate = false;
      }
    }
  },
  methods: {
    /* 保存编辑 */
    approve() { 
      let mark = 2;
      this.$http.post('/spbcinvset/updateMark/'+this.form.id+'/'+mark).then(res => {
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.$emit('done');
          this.updateVisible(false);
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>

<style scoped>
  .el-form-item {
    margin-bottom:3px;
  }
</style>
